// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   registerInit_start_ok.java

package finance.teller.checkup;

import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;
import validata.ValidataNumber;

public class registerInit_start_ok extends HttpServlet
{

	public registerInit_start_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		javax.servlet.ServletContext dbApplication = dbSession.getServletContext();
		PrintWriter out = response.getWriter();
		HttpSession session = request.getSession();
		nseer_db_backup1 finance_db = new nseer_db_backup1(dbApplication);
		ValidataNumber validata = new ValidataNumber();
		try
		{
			if (finance_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String file_id = request.getParameter("file_id");
				String balance_sum = request.getParameter("balance_sum");
				String balance_sum1 = request.getParameter("balance_sum1");
				if (validata.validata(balance_sum) && validata.validata(balance_sum1))
				{
					String sql2 = (new StringBuilder("select id from finance_bill where tag='1' and file_id='")).append(file_id).append("'").toString();
					ResultSet rs2 = finance_db.executeQuery(sql2);
					String sql = "";
					if (rs2.next())
						sql = (new StringBuilder("update finance_bill set debit_subtotal='")).append(balance_sum1).append("' where tag='1' and file_id='").append(file_id).append("'").toString();
					else
						sql = (new StringBuilder("insert into finance_bill(debit_subtotal,file_id,tag) values('")).append(balance_sum1).append("','").append(file_id).append("','1')").toString();
					finance_db.executeUpdate(sql);
					sql2 = (new StringBuilder("select id from finance_voucher where account_period='18' and chain_id='")).append(file_id).append("'").toString();
					rs2 = finance_db.executeQuery(sql2);
					if (rs2.next())
						sql = (new StringBuilder("update finance_voucher set debit_subtotal='")).append(balance_sum).append("' where account_period='18' and chain_id='").append(file_id).append("'").toString();
					else
						sql = (new StringBuilder("insert into finance_voucher(debit_subtotal,chain_id,account_period) values('")).append(balance_sum).append("','").append(file_id).append("','18')").toString();
					finance_db.executeUpdate(sql);
					finance_db.commit();
					finance_db.close();
				} else
				{
					out.println("1");
				}
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
